package com.tjbank.cssys.web.service.impl;

import com.alibaba.fastjson.JSON;
import com.tjbank.cssys.domain.CkOrderAccountAgeForm2;
import com.tjbank.cssys.domain.CkOrderOutboundForm;
import com.tjbank.cssys.domain.CkOrderRecoveryData;
import com.tjbank.cssys.repository.CkOrderRecoveryDataMapper;
import com.tjbank.cssys.web.service.CkOrderOutboundFormService;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

@Service
public class CkOrderOutboundFormServiceImpl implements CkOrderOutboundFormService {
    protected static final Logger logger = LoggerFactory.getLogger(CkOrderOutboundFormServiceImpl.class);
    @Autowired
    private CkOrderRecoveryDataMapper ckOrderRecoveryDataMapper;
    @Override
    public List<CkOrderOutboundForm> selectAllCkOrderOutboundForm(String dateTime) {
        try {
            logger.info("获取外呼产能列表2start---参数：param:"+dateTime);
            dateTime="%"+dateTime+"%";
            List<CkOrderOutboundForm> ckOrderOutboundFormList = ckOrderRecoveryDataMapper.selectAllCkOrderOutboundForm(dateTime);
            if (CollectionUtils.isEmpty(ckOrderOutboundFormList)) {
                return null;
            } else {
                Iterator<CkOrderOutboundForm> iterator = ckOrderOutboundFormList.iterator();
                while (iterator.hasNext()) {
                    CkOrderOutboundForm next = iterator.next();
                    String channel = next.getChannel();
                    if ("短信".equalsIgnoreCase(channel)) {
                        iterator.remove();
                    } else {
                        dateTime=dateTime.replaceAll("%","").replaceAll("-","");
                        next.setDate(dateTime);
                    }
                }
            }
            logger.info("获取外呼产能列表结束----返回值:"+ JSON.toJSONString(ckOrderOutboundFormList));
            return ckOrderOutboundFormList;
        } catch (Exception e) {
            logger.error("获取外呼产能列表失败",e);
           throw e;
        }
    }
}
